package edu.testdemo.dao.impl;

import edu.nf.SQLExecutor;
import edu.nf.beans.annotations.Component;
import edu.nf.handler.BeanHandler;
import edu.nf.handler.MapListHandler;
import edu.testdemo.dao.UsersDao;
import edu.testdemo.model.Users;
import edu.testdemo.utils.ConnUtil;

import java.util.List;
import java.util.Map;

@Component("userDao")
public class UsersDaoImpl implements UsersDao{

    private SQLExecutor se = null;

    @Override
    public Users findUser(String userName, String password) {
        String sql = "SELECT * FROM USER_INFO WHERE U_NAME = ? AND U_PASSWORD = ?";
        se = new SQLExecutor(ConnUtil.getConnection());
        BeanHandler<Users> handler = new BeanHandler<>(Users.class);
        return se.executeQuery(sql, handler, userName, password);
    }

    @Override
    public List<Map<String,Object>> getAllUsers() {

        String sql = "select * from USER_INFO";
        se = new SQLExecutor(ConnUtil.getConnection());
        MapListHandler handler = new MapListHandler();
        List<Map<String,Object>> list = se.executeQuery(sql,handler);
        return list;
        /*BeanHandler<Users> handler = new BeanHandler<>(Users.class);
        List<Users> Users = se.executeQuery(sql, handler);
        return Users;*/
    }

    @Override
    public void deleteUsers(int uid) {
        String sql="DELETE FROM USER_INFO WHERE U_ID = ?";
        se = new SQLExecutor(ConnUtil.getConnection());
        se.executeUpdate(sql,uid);
    }

    @Override
    public void updateUsers(int uid) {
        String sql="SELECT * FROM WHERE U_ID = ?";
        se = new SQLExecutor(ConnUtil.getConnection());
        se.executeUpdate(sql,uid);
    }

}
